﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ElevateThis
{
    /// <summary>
    /// A collection of command line arguments
    /// </summary>
    public class CommandLineArgs
    {
        List<CommandLineArg> _args = new List<CommandLineArg>();

        /// <summary>
        /// Construct command line arguments collection from strings provided at the command line
        /// </summary>
        public CommandLineArgs(string[] args)
        {
            // Loop over the command line arguments
            CommandLineArg currentArg = null;
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].StartsWith("/"))
                {
                    // Start of new argument, so add the last argument to our dictionary
                    if (currentArg != null) _args.Add(currentArg);
                    currentArg = new CommandLineArg(args[i]);
                }
                else if (currentArg != null)
                {
                    // Append value to current argument
                    currentArg.AppendValue(args[i]);
                }
            }

            // Finally, add the remaining arg
            if (currentArg != null) _args.Add(currentArg);
        }

        public IEnumerator<CommandLineArg> GetEnumerator()
        {
            return _args.GetEnumerator();
        }

    }

}
